<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

    class Object_gallery_lib{

        public function __construct(){

            $this->CI = &get_instance();
            $this->CI->load->model("objects_gallery_model");
        }

        /**
        * 
        * Show error message
        * @param $str error string
        */        
        private function throwError($str){
            echo $str;
            exit();
        }

        public function add($object_id,$gallery_id)
        {
            // insert into objects_gallery  
            $insert_id = $this->CI->objects_gallery_model->insert(array('objects_ID'=>$object_id,'gallery_ID'=>$gallery_id));

            return TRUE;
        } 

        function find_gallery_column($object_id,$column)
        {
            // get gallery folder name
            $gallery = $this->CI->objects_gallery_model->find_object_gallery($object_id);
            if(!isset($gallery['path']))
            {
                $this->throwError('No gallery associated with this object :)');
                return;
            }
            return $gallery[$column];
        }

        function delete_thumbnails_dir($object_id,$thumbnails)
        {
            // delete directories
            foreach ($thumbnails as $thumbnail) :
                $size = unserialize($thumbnail['user_data']);
                $name = "thumb_".$size['w'].'x'.$size['h'];

                $path_name = "./".config_item('gallery_folder')."/"."gallery_".$object_id."/".$name;
                //$this->firephp->log($path_name);

                if(!delete_folder($path_name)) 
                    //$this->throwError('create thumbnail folder for gallery fails:)');
                    echo "Fodler not found. ".$path_name."<br>";

                endforeach;

        }

    }

?>
